import { defineStore } from "pinia";
import { ref } from "vue";

export const useExchangeStore = defineStore("exchange", () => {
  // 状态使用 ref 来定义
  const selectedItems = ref([]);
  const addedItems = ref([]);

  // actions 改写成普通函数
  const setSelectedItems = (items) => {
    selectedItems.value = items;
  };

  const clearSelectedItems = () => {
    selectedItems.value = [];
  };

  const setAddedItems= (items) => {
    addedItems.value = items;
  };

  const clearAddedItems = () => {
    addedItems.value = [];
  };


  //扫码收银数据
  const scanData = ref({});
  const setScanData = (items) => {
    scanData.value = items;
  };
  const clearScanData = () => {
    scanData.value = [];
  };

  // 返回所有状态和方法
  return {
    selectedItems,
    setSelectedItems,
    clearSelectedItems,

    addedItems,
    setAddedItems,
    clearAddedItems,

    scanData,
    setScanData,
    clearScanData
  };
});